class UsersController < ApplicationController
    layout nil
    
    include UsersHelper
    
    def index
        getSQLCondition params
        if request.xhr?
            if (getSQLCondition params).size > 0
                @users = loadUsers params[:start], params[:offset], getSQLCondition(params)
            else
                @users = loadUsers params[:start], params[:offset]
            end
        end
        render :text => @users
    end
    
    def total_count
        if request.xhr?
          # Connection
          connection = ActiveRecord::Base.connection
        
          #Prepare SQL String
          if (getSQLCondition params).size > 0
              strSQL = "SELECT COUNT(*) AS 'total_count' FROM VW_Employee WHERE #{getSQLCondition(params)};"
          else
              strSQL = "SELECT COUNT(*) AS 'total_count' FROM VW_Employee;"
          end
          # Doing select
          hash_set = connection.select_all strSQL
        
          @count = hash_set[0]["total_count"]
        end
        render :text => @count
    end

end
